package com20230218;

import java.util.Arrays;

public class Insert {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        insertElement(arr,6,9);
    }

    public static void insertElement(int[] arr,int index,int num){

            arr = Arrays.copyOf(arr, arr.length+1);
        for (int i = 0; i < arr.length; i++) {
            if (i == index){
                System.arraycopy(arr,i,arr,i+1,arr.length - index-1);
                arr[i] = num;

            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
